//
//  LSPersonalHomePageCharmCell.m
//  LookScore
//
//  Created by wr on 2017/12/18.
//  Copyright © 2017年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSPersonalHomePageCharmCell.h"

@interface LSPersonalHomePageCharmCell()

@property(strong,nonatomic)UIImageView *headImgView;

@property(strong,nonatomic)UILabel *nameLab;

@property(strong,nonatomic)UILabel *charmLab;

@property(nonatomic,strong)UILabel * topicLabel;



@property(copy,nonatomic)NSString *cidStr;

@end
@implementation LSPersonalHomePageCharmCell

+(LSPersonalHomePageCharmCell *)PersonalHomePageCharmCellByTableView:(UITableView *)tableView{
 
    LSPersonalHomePageCharmCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell=[[LSPersonalHomePageCharmCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        
    }
    return cell;
}

//-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
//
//    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
//    if (self) {
//        self.backgroundColor=[UIColor whiteColor];
//        [self addContentView];
//    }
//
//    return self;
//}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addContentView];
    }
    return self;
}
-(void)addContentView{
    
    UIImageView *headImage=[[UIImageView alloc]init];
    
//    headImage.layer.masksToBounds=YES;
//    headImage.layer.cornerRadius=2;
    [self.contentView addSubview:headImage];
    headImage.userInteractionEnabled=YES;
    self.headImgView = headImage; headImage.sd_layout.leftEqualToView(self.contentView).offset(LSSpaceLeftWidth1).centerYEqualToView(self.contentView).widthIs(50).heightEqualToWidth();
    
    UILabel *nameLab=[[UILabel alloc]init];
    nameLab.font=LSFontSize13;
    nameLab.text = @"忧郁有度";
    nameLab.textColor=LSTitleGrayColor1;
    nameLab.textAlignment=NSTextAlignmentLeft;
    
    [self.contentView addSubview:nameLab];
    self.nameLab=nameLab;
    nameLab.sd_layout.leftSpaceToView(headImage, 6).topEqualToView(headImage).heightIs(20).autoWidthRatio(10);
    
    UILabel * topicLabel = [[UILabel alloc] init];
    topicLabel.font = LSFontSize13;
    topicLabel.text = @"话题（0）";
    topicLabel.textColor = LSTitleGrayColor2;
    [self.contentView addSubview:topicLabel];
    self.topicLabel = topicLabel;
    topicLabel.sd_layout.leftSpaceToView(headImage, 6).bottomEqualToView(headImage).heightIs(20);
    [topicLabel setSingleLineAutoResizeWithMaxWidth:180];//宽度自适应
    
    
    
    UILabel *charmLab=[[UILabel alloc]init];
    charmLab.font=LSFontSize13;
    charmLab.text = @"粉丝（0）";
    charmLab.textColor=LSTitleGrayColor2;
    charmLab.textAlignment=NSTextAlignmentLeft;
    [self.contentView addSubview:charmLab];
    self.charmLab=charmLab;
    charmLab.sd_layout.leftSpaceToView(topicLabel, 10).centerYEqualToView(topicLabel).heightIs(20).autoWidthRatio(10);
    
    
    UIButton *attentionBu=[[UIButton alloc]init];
    attentionBu.selected=NO;
//    attentionBu.titleLabel.textColor=LSTitleWhiteColor;
    attentionBu.titleLabel.font=LSFontSize10;
    [attentionBu setImage:[UIImage imageNamed:@"attend"] forState:UIControlStateNormal];
    [attentionBu setImage:[UIImage imageNamed:@"selectAttend"] forState:UIControlStateSelected];
//    [attentionBu setTitle:@"+关注" forState:UIControlStateNormal];
    attentionBu.layer.masksToBounds=YES;
    attentionBu.layer.cornerRadius=8;
    [attentionBu addTarget:self action:@selector(attentionEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:attentionBu];
    self.attentionBu=attentionBu;
    attentionBu.sd_layout.rightSpaceToView(self.contentView, 10).centerYEqualToView(headImage).widthIs(55).heightIs(24);
    
    
    
    UIView *lineView=[[UIView alloc]init];
    lineView.backgroundColor=LSLineGrayColor;
    [self.contentView addSubview:lineView];
    lineView.sd_layout.leftEqualToView(self.contentView).bottomEqualToView(self.contentView).rightEqualToView(self.contentView).heightIs(.5f);
    
}
- (void)setModel:(LSPersonalHomePageCharmModel *)model{
    _model = model;
    self.nameLab.text = model.DisplayName;
    
    self.topicLabel.text = [NSString stringWithFormat:@"话题（%@）",model.TopicPublishCount];
    
    self.charmLab.text = [NSString stringWithFormat:@"粉丝（%@）",model.FansCount];
    
    self.attentionBu.selected = model.IsAttended;
    
    self.cidStr = model.Cid;
    
    [self.headImgView sd_setImageWithURL:[NSURL URLWithString:model.UserHeadUrl] placeholderImage:[UIImage imageNamed:@"MineDefaultHead"] options:SDWebImageRefreshCached];
    

    
}

- (void)attentionEvent:(UIButton *)sender{
    sender.selected = !sender.selected;
    
    if ([_delegate respondsToSelector:@selector(attentionEvent:CidString:)]) {
        [_delegate attentionEvent:sender CidString:self.cidStr];
    }
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end





@interface LSPersonalHomePageScreenCell()

@property(strong,nonatomic)UIImageView *headImgView;

@property(strong,nonatomic)UILabel *nameLab;

@property(strong,nonatomic)UILabel *charmLab;

@property(nonatomic,strong)UILabel * topicLabel;



@property(copy,nonatomic)NSString *cidStr;

@end
@implementation LSPersonalHomePageScreenCell

+(LSPersonalHomePageScreenCell *)PersonalHomePageScreenCellByTableView:(UITableView *)tableView{
    
    LSPersonalHomePageScreenCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell=[[LSPersonalHomePageScreenCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addContentView];
    }
    return self;
}
-(void)addContentView{
    
    UIImageView *headImage=[[UIImageView alloc]init];
    
    [self.contentView addSubview:headImage];
    headImage.userInteractionEnabled=YES;
    self.headImgView = headImage; headImage.sd_layout.leftEqualToView(self.contentView).offset(LSSpaceLeftWidth1).centerYEqualToView(self.contentView).widthIs(50).heightEqualToWidth();
    
    UILabel *nameLab=[[UILabel alloc]init];
    nameLab.font=LSFontSize13;
    nameLab.textColor=LSTitleGrayColor1;
    nameLab.textAlignment=NSTextAlignmentLeft;
    
    [self.contentView addSubview:nameLab];
    self.nameLab=nameLab;
    nameLab.sd_layout.leftSpaceToView(headImage, 6).topEqualToView(headImage).heightIs(20).autoWidthRatio(10);
    
    
    
    
    UIButton *attentionBu=[[UIButton alloc]init];
    attentionBu.selected=NO;
    //    attentionBu.titleLabel.textColor=LSTitleWhiteColor;
    attentionBu.titleLabel.font=LSFontSize10;
    [attentionBu setImage:[UIImage imageNamed:@"isSelectScreen"] forState:UIControlStateNormal];
    [attentionBu setImage:[UIImage imageNamed:@"isSelectScreen"] forState:UIControlStateSelected];
    //    [attentionBu setTitle:@"+关注" forState:UIControlStateNormal];
    attentionBu.layer.masksToBounds=YES;
    attentionBu.layer.cornerRadius=8;
    [attentionBu addTarget:self action:@selector(attentionEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:attentionBu];
    self.attentionBu=attentionBu;
    attentionBu.sd_layout.rightSpaceToView(self.contentView, 10).centerYEqualToView(headImage).widthIs(55).heightIs(24);
    
    
    
    UIView *lineView=[[UIView alloc]init];
    lineView.backgroundColor=LSLineGrayColor;
    [self.contentView addSubview:lineView];
    lineView.sd_layout.leftEqualToView(self.contentView).bottomEqualToView(self.contentView).rightEqualToView(self.contentView).heightIs(.5f);
    
}
- (void)setModel:(LSPersonalHomePageCharmModel *)model{
    _model = model;
    self.nameLab.text = model.DisplayName;
    
    
    self.attentionBu.selected = model.IsAttended;
    
    self.cidStr = model.Cid;
    
    [self.headImgView sd_setImageWithURL:[NSURL URLWithString:model.UserHeadUrl] placeholderImage:[UIImage imageNamed:@"MineDefaultHead"] options:SDWebImageRefreshCached];
    
}

- (void)attentionEvent:(UIButton *)sender{
    sender.selected = !sender.selected;
    
    if ([_delegate respondsToSelector:@selector(screenEvent:CidString:)]) {
//        [_delegate attentionEvent:sender CidString:self.cidStr];
        [_delegate screenEvent:sender CidString:self.cidStr];
    }
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end

